﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Factonomy.AzureStorageUtility.WindowsApp.Azure;
using Factonomy.AzureStorageUtility.WindowsApp.Azure.Storage;
using Factonomy.AzureStorageUtility.WindowsApp.Resources;

namespace Factonomy.AzureStorageUtility.WindowsApp.UI.Forms
{
    public partial class ImageViewer : Form
    {
        private string _accountName = string.Empty;
        private string _containerName = string.Empty;
        private string _blobName = string.Empty;
        private Image _image = null;

        public ImageViewer(string accountName, string containername, string blobName)
        {
            try
            {
                InitializeComponent();

                // set the window icon
                this.Icon = ResourceManager.GetAppIcon();

                this._accountName = accountName;
                this._containerName = containername;
                this._blobName = blobName;

                this.uiCloseToolStripMenuItem.Click += new EventHandler(uiCloseToolStripMenuItem_Click);

                using (BlobManager blob = new BlobManager())
                {
                    blob.Load(this._accountName);
                    MemoryStream stream = blob.GetBlobContents(this._containerName, this._blobName);
                    this._image = Image.FromStream(stream);
                }

                if (this._image != null)
                {
                    this.uiPictureBox.Image = this._image;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }

        void uiCloseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
